<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加新闻类型</title>
    <link href="../../css/admin/style.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.8.3.min.js" type="text/javascript"></script >
    <script type="text/javascript">
        var check = 0;
        function checkName(){
            var journame = $("input[name='journame']").val();
            if (journame == ""){
                $("#checkSpan").html("新闻类型不能为空");
                check = 1;
                return ;
            }
            $.get("../../newstype/checkName",{journame:journame},function (res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else if (res.code == 201){
                    $("#checkSpan").html(res.msg);
                    check = 1;
                }else {
                    $("#checkSpan").html(res.msg);
                    check = 0;
                }
            })
        }

        //保存
        function save() {
            if (check==1){
                alert("该新闻类型已存在，请重新输入或返回！");
                return ;
            }
            $.post("../../newstype/savenewstype", $("#formId").serialize(), function (res) {
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                } else {
                    alert("保存成功");
                    location.replace("list.html");
                }
            });
        }

    </script>


</head>

<body>
<div class="formbody">
    <div class="formtitle"><span>基本信息</span></div>
    <form id="formId">
        <ul class="forminfo">
            <!--楼栋管理员表 Id,姓名,性别,年龄,电话,家庭地址,入职时间,楼栋id,操作人,操作时间-->
            <li>
                <label>新闻类型名</label>
                <input name="journame" type="text" class="dfinput" onblur="checkName()"/>
                <span id="checkSpan"></span>
            </li>

            <li>
                <input name="" type="button"  value="确认保存" onclick="save()"/>
            </li>
        </ul>
    </form>
</div>

</body>

</html>
